﻿using CashFlow.ShopManage.Service;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

using AutoFacUtils;
using CashFlow.Db.Entity;
using CashFlow.ShopManage.Def.Models;
using CashFlow.ShopManage.Models.ShopPerformance;
using CashFlow.ShopManage.Models.ShopPerformance.Result;
using CashFlow.ShopManage.Common;

namespace CashFlow.ShopManage.Controllers
{
    public class ShopPerformanceController : Controller
    {
        private IAdminService GetAdminService() { return AutoFacHelper.Get<IAdminService>(); }
        private IShopPerformanceService GetShopPerformanceService() { return AutoFacHelper.Get<IShopPerformanceService>(); }

        // GET: ShopPerformance
        public ActionResult Index()
        {
            return View();
        }

        public ActionResult List(string date)
        {
            var adminService = GetAdminService();
            var ui = adminService.GetLoginUserInfo();
            var shopPerormanceService = GetShopPerformanceService();
            var ls = shopPerormanceService.QueryByWhere(ui.ShopManagerUserId, date);
            var ls2 = ls.Select(x => Convert(x)).ToList();
            return MyCommonTool.CreateLayUITableResult(true, "", ls2, ls2.Count);
        }

        private QueryShopPerformanceModelResult Convert(
            ShopPerformanceEntity model)
        {
            return new QueryShopPerformanceModelResult
            {
                Date = model.Date,
                OrderAmountTotal = model.OrderAmountTotal,
                OrderTotal = model.OrderTotal,
                BonusFee = model.BonusFee,
                ConsignmentSaleFee = model.ConsignmentSaleFee,
                OrderAmountAvg = model.OrderAmountAvg,
                AmountFrom0KTo1K = model.AmountFrom0KTo1K,
                AmountFrom1KTo2K = model.AmountFrom1KTo2K,
                AmountFrom2KTo3K = model.AmountFrom2KTo3K,
                AmountFrom3KTo4K = model.AmountFrom3KTo4K,
                AmountFrom4KTo5K = model.AmountFrom4KTo5K,
                AmountFrom5KTo6K = model.AmountFrom5KTo6K,
                AmountFrom6KTo7K = model.AmountFrom6KTo7K,
                AmountFrom7KTo8K = model.AmountFrom7KTo8K,
                AmountFrom8KTo9K = model.AmountFrom8KTo9K,
                AmountFrom9KTo10K = model.AmountFrom9KTo10K,
                AmountFrom10KTo11K = model.AmountFrom10KTo11K,
                AmountFrom11KTo12K = model.AmountFrom11KTo12K,
                AmountFrom12KTo13K = model.AmountFrom12KTo13K,
                AmountFrom13KTo14K = model.AmountFrom13KTo14K,
                AmountFrom14KTo15K = model.AmountFrom14KTo15K
            };
        }
    }
}